package com.cys.dm.rest.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cys.dm.dao.user.DmLinkUserDao;
import com.cys.dm.entity.user.DmLinkUser;
import org.bouncycastle.cert.ocsp.Req;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author blue_t
 * @date 2020-12-23 18:29
 */
@RestController
@RequestMapping(path = "/user")
public class DmLinkUserService {
    @Resource
    private DmLinkUserDao dmLinkUserDao;

    @PostMapping(path = "/findAllByUserId/{userId}")
    public List<DmLinkUser> findAllByUserId(@PathVariable("userId")Long userId){
        QueryWrapper<DmLinkUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId",userId);
        return dmLinkUserDao.selectList(queryWrapper);
    }

    @PostMapping(path = "/queryLinkUserByIdCard/{idCard}")
    public DmLinkUser queryLinkUserByIdCard(@PathVariable("idCard")Long idCard){
        QueryWrapper<DmLinkUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("idCard",idCard);
        return dmLinkUserDao.selectOne(queryWrapper);
    }

    @PostMapping(path = "/addLinkUser")
    public Integer addLinkUser(@RequestBody DmLinkUser dmLinkUser){
        return dmLinkUserDao.insert(dmLinkUser);
    }

    /**
     * 根据身份证号查询订单常用联系人
     * @param idCard 身份证号
     * @return
     */
    @PostMapping(path = {"findLinkUserByIdCard/{idCard}"})
    public DmLinkUser findLinkUserByIdCard(@PathVariable("idCard")Long idCard){
        QueryWrapper<DmLinkUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("idCard",idCard);
        return dmLinkUserDao.selectOne(queryWrapper);
    }


}
